package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.course.Course;
import com.hualan.sfzy.service.course.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CourseController {
    @Autowired
    private CourseService courseService;
    @PostMapping("/course")
    public String add(@RequestBody Course course) {
        return courseService.add(course)>0?"success":"fail";
    }
    @DeleteMapping("/course/{id}")
    public String remove(@PathVariable int id) {
        return courseService.remove(id)>0?"success":"fail";
    }
    @DeleteMapping("/course")
    public String removeBatch(Integer[] ids) {
        return courseService.removeBatch(ids)>0?"success":"fail";
    }
    @PutMapping("/course")
    public String edit(@RequestBody Course course) {
        return courseService.update(course)>0?"success":"fail";
    }
    @GetMapping("/course")
    public List<Course> find() {
        return courseService.find();
    }
    @GetMapping("/course/{id}")
    public Course findById(@PathVariable int id) {
        return courseService.findById(id);
    }
    @GetMapping("/course/page")
    public Object findPage(
            @RequestParam(value = "pageNum",defaultValue = "1",required = false)
            Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5",required = false)
            Integer pageSize,
            Course course
    ) {
        return courseService.findPage(pageNum,pageSize,course);
    }
}

